package com.ymatou.iapi.godmch.testcase;

import java.util.List;

import org.junit.After;
import org.junit.AfterClass;
import org.junit.Before;
import org.junit.BeforeClass;
import org.junit.Test;
import org.junit.experimental.categories.Category;

import com.ymatou.iapi.dguser.parameter.UserCreateBean;
import com.ymatou.iapi.godmch.parameter.CreateCodeBean;
import com.ymatou.iapi.godmch.parameter.createmchBean;
import com.ymatou.iapi.godmch.parameter.editRemarkagentBean;
import com.ymatou.iapi.godmch.service.editRemarkagentCall;
import com.ymt.core.tool.Logger;
import com.ymt.utils.annotation.*;
import com.ymt.utils.tag.*;
import com.ymttest.business.service.DGUserCallService;
import com.ymttest.business.service.shenqi.GodmchManageCallService;
import com.ymttest.database.model.mch_relation;
import com.ymttest.database.sqlwapper.godmch.DefGodMchWapper;
import com.ymttest.utils.TestDataManager;

/**
 * 设置代理商备注 FreeMaker Template自动生成代码
 */
@TestSuite
public class Ts_editRemarkagent {
	private static editRemarkagentBean bean;
	private static editRemarkagentCall call;
	DefGodMchWapper DefGodMchWapper;

	@BeforeClass
	public static void setUp() {
		Logger.createResultFile("设置代理商备注");
	}

	@Before
	public void caseUp() {
		bean = new editRemarkagentBean();
		call = new editRemarkagentCall();
		DefGodMchWapper = new DefGodMchWapper();
	}

	@AfterClass
	public static void tearDown() {
		Logger.generateResult(call.getOpurl());
	}

	@After
	public void caseDown() {
		Logger.end();
	}

	@Test
	@Category({ P1.class })
	@TestCase
	public void Tc_editRemarkagent_001() {
		Logger.start(true, "设置代理商备注,验证商户id和代理商id同时存在-返回正常");
		try {
			CreateCodeBean ccbean = GodmchManageCallService.CreateAllMsgSellerMch();
			String code = GodmchManageCallService.createCodeCall(ccbean).getCode();
			Integer agentid = GodmchManageCallService.CreateSellerMch(code);

			String remark = "测试备注_" + TestDataManager.getPhoneNum();
			bean.setMchId(ccbean.getMchId());
			bean.setAgentId(agentid);
			bean.setRemark(remark);
			call.setData(bean);
			call.callService();
			Logger.verifyEquals("200", call.getString("status"), "验证status");
			mch_relation dbmr = DefGodMchWapper.selectMchRelation(ccbean.getMchId(), agentid, ccbean.getRoleType()).get(0);
			Logger.verifyEquals(bean.getRemark(), dbmr.getRemark(), "验证remark");
		} catch (Exception e) {
			Logger.fail(e);
		}
	}

	@Test
	@Category({ P1.class })
	@TestCase
	public void Tc_editRemarkagent_002() {
		Logger.start(true, "设置代理商备注,验证商户id与代理商id不匹配-返回错误");
		try {
			CreateCodeBean ccbean2 = GodmchManageCallService.CreateAllMsgSellerMch();
			CreateCodeBean ccbean = GodmchManageCallService.CreateAllMsgSellerMch();
			String code = GodmchManageCallService.createCodeCall(ccbean).getCode();
			Integer agentid = GodmchManageCallService.CreateSellerMch(code);

			String remark = "测试备注_" + TestDataManager.getPhoneNum();
			bean.setMchId(ccbean2.getMchId());
			bean.setAgentId(agentid);
			bean.setRemark(remark);
			call.setData(bean);
			call.callService();
			Logger.verifyEquals("5002", call.getString("status"), "验证status");

		} catch (Exception e) {
			Logger.fail(e);
		}
	}

	@Test
	@Category({ P1.class })
	@TestCase
	public void Tc_editRemarkagent_003() {
		Logger.start(true, "设置代理商备注,验证商户id不存在,返回错误");
		try {
			CreateCodeBean ccbean = GodmchManageCallService.CreateAllMsgSellerMch();
			String code = GodmchManageCallService.createCodeCall(ccbean).getCode();
			Integer agentid = GodmchManageCallService.CreateSellerMch(code);

			String remark = "测试备注_" + TestDataManager.getPhoneNum();
			bean.setMchId(1);
			bean.setAgentId(agentid);
			bean.setRemark(remark);
			call.setData(bean);
			call.callService();
			Logger.verifyEquals("5002", call.getString("status"), "验证status");

		} catch (Exception e) {
			Logger.fail(e);
		}
	}

	@Test
	@Category({ P1.class })
	@TestCase
	public void Tc_editRemarkagent_004() {
		Logger.start(true, "设置代理商备注,验证商户id为空,返回错误");
		try {
			// bean.setMchId(ccbean2.getMchId());
			bean.setAgentId(1);
			bean.setRemark("remark");
			call.setData(bean);
			call.callService();
			Logger.debug(call.getStatusCode());
			Logger.verifyEquals("4001", call.getString("status"), "验证status");

		} catch (Exception e) {
			Logger.fail(e);
		}
	}

	@Test
	@Category({ P1.class })
	@TestCase
	public void Tc_editRemarkagent_005() {
		Logger.start(true, "设置代理商备注,验证代理商id不存在,返回错误");
		try {

			CreateCodeBean ccbean = GodmchManageCallService.CreateAllMsgSellerMch();
			String code = GodmchManageCallService.createCodeCall(ccbean).getCode();
			Integer agentid = GodmchManageCallService.CreateSellerMch(code);

			String remark = "测试备注_" + TestDataManager.getPhoneNum();
			bean.setMchId(1);
			bean.setAgentId(agentid + 1);
			bean.setRemark(remark);
			call.setData(bean);
			call.callService();
			Logger.verifyEquals("5002", call.getString("status"), "验证status");
		} catch (Exception e) {
			Logger.fail(e);
		}
	}

	@Test
	@Category({ P1.class })
	@TestCase
	public void Tc_editRemarkagent_006() {
		Logger.start(true, "设置代理商备注,验证代理商id为空,返回错误");
		try {
			bean.setMchId(1);
			// bean.setAgentId(1);
			bean.setRemark("remark");
			call.setData(bean);
			call.callService();
			Logger.debug(call.getStatusCode());
			Logger.verifyEquals("4001", call.getString("status"), "验证status");

		} catch (Exception e) {
			Logger.fail(e);
		}
	}

	@Test
	@Category({ P1.class })
	@TestCase
	public void Tc_editRemarkagent_007() {
		Logger.start(true, "设置代理商备注,验证备注为空,返回错误");
		try {
			bean.setMchId(1);
			bean.setAgentId(1);
			// bean.setRemark("remark");
			call.setData(bean);
			call.callService();
			Logger.debug(call.getStatusCode());
			Logger.verifyEquals("4001", call.getString("status"), "验证status");

		} catch (Exception e) {
			Logger.fail(e);
		}
	}
}